<template>
    <div class="form">
        <el-form label-width="auto" :rules="formRules" ref="formRef" :model="inspection">
            <el-form-item label="审核结果" prop="findingOfAudit">
                <el-select v-model="inspection.findingOfAudit" placeholder="审核结果" style="width: 400px">
                    <el-option v-for="item in options" :key="item.value" :label="item.label" :value="item.value" />
                </el-select>
            </el-form-item>
            <el-form-item label="备注">
                <el-input v-model="inspection.notes" placeholder="备注"></el-input>
            </el-form-item>
            <el-form-item>
                <el-button type="primary" @click="save">保存</el-button>
                <el-button type="info" @click="cancel">取消</el-button>
            </el-form-item>
        </el-form>
    </div>
</template>

<script setup>
import http from '../utils/http'
import { ref } from 'vue'
import { ElMessageBox } from 'element-plus'
import { useRouter } from 'vue-router';
import { onBeforeMount } from 'vue';
let router = useRouter()

const options = [
    {
        value: '同意',
        label: '同意',
    },
    {
        value: '拒绝',
        label: '拒绝',
    }
]
let inspection = ref({
    findingOfAudit: '',
    notes: ''
})

let formRef = ref(null)//表单dom对象
let formRules = ref({
    findingOfAudit: [
        { required: true, message: '停车场类型',trigger:'blur'}
    ],
})
onBeforeMount(async () => {
    if (inspection.value.id) {
        let resp = await http.get(`/inspection/get/${inspection.value.id}`)
        inspection.value = resp.data
    }
})
async function save() {
    let path = inspection.value.id ? '/inspection/update' : '/inspection/add'
    let tip = inspection.value.id ? '修改' : '保存'
    let resp = await http.post(path, inspection.value)
    if (resp.code == 200) {
        ElMessageBox.alert(tip + '账户成功', tip + '账户', {
            confirmButtonText: 'OK'
        })
        router.go(-1)
    } else {

    }
}
function cancel() {
    router.go(-1)
}

</script>
<style lang="css" scoped>
.form {
    width: 400px;
    margin: 0 auto;
}

.el-form-item__label {
    width: 120px;
}
</style>